#!/usr/bin/python3.8
# -*- coding: utf-8 -*-
# @Time    : 2021/3/2 08:46
# @Author  : zhaohexin
# @Email   : 1483643520@xxx.com
# @File    : schemas.py
# @Software: PyCharm
# @FileDescription： Pydantic模型 - 传入参数类型校验 - 自定义校验

from datetime import datetime
from typing import Optional
from pydantic import BaseModel
from typing import List

from common.BaseSchemas import BaseSchemas
from apps.system.roles import schemas as roleSchemas
from apps.system.jobs import schemas as jobSchemas
from apps.system.depts import schemas as deptSchemas


class UserBase(BaseSchemas):
    """
    用户通用校验
    """
    dept_id: int
    username: str
    nick_name: str
    gender: Optional[str] = "未知"
    phone: Optional[str] = None
    email: Optional[str] = None
    avatar_name: Optional[str] = None
    avatar_path: Optional[str] = None
    is_admin: Optional[bool] = False
    enabled: Optional[bool] = False
    pwd_reset_time: Optional[datetime] = None


class UserCreate(UserBase):
    """
    创建用户校验器
    """
    password: str


class User(UserBase):
    """
    查询用户校验器
    """
    pass


class UserWeb(BaseModel):
    """
    需要返回前端数据校验
    """
    avatarName: str
    avatarPath: str
    createTime: str
    dept_id: int
    email: str
    enabled: bool
    gender: str
    id: int
    nickName: str
    phone: str
    pwdResetTime: str
    updateTime: str
    updateBy: str
    createBy: str
    username: str


class UserWebManage(UserWeb):
    roles: List[roleSchemas.RolesWeb]
    jobs: List[jobSchemas.JobsWeb]
    dept: deptSchemas.DeptsWeb


class UsersWeb(BaseModel):
    """
    需要返回前端全部用户数据校验
    """
    content: List[UserWebManage]
    totalElements: int
